package com.ruoyi.his.service.impl;

import java.util.List;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.his.mapper.NewHisScheduleMapper;
import com.ruoyi.his.domain.NewHisSchedule;
import com.ruoyi.his.service.INewHisScheduleService;

/**
 * newscheduleService业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-14
 */
@Service
public class NewHisScheduleServiceImpl implements INewHisScheduleService 
{
    @Autowired
    private NewHisScheduleMapper newHisScheduleMapper;

    /**
     * 查询newschedule
     * 
     * @param schedId newschedule主键
     * @return newschedule
     */
    @Override
    public NewHisSchedule selectNewHisScheduleBySchedId(Long schedId)
    {
        return newHisScheduleMapper.selectNewHisScheduleBySchedId(schedId);
    }

    /**
     * 查询newschedule列表
     * 
     * @param newHisSchedule newschedule
     * @return newschedule
     */
    @Override
    public List<NewHisSchedule> selectNewHisScheduleList(NewHisSchedule newHisSchedule)
    {
        return newHisScheduleMapper.selectNewHisScheduleList(newHisSchedule);
    }

    /**
     * 新增newschedule
     * 
     * @param newHisSchedule newschedule
     * @return 结果
     */
    @Override
    public int insertNewHisSchedule(NewHisSchedule newHisSchedule)
    {
        //检查当天是否已有挂号
       int check =  newHisScheduleMapper.check(newHisSchedule);
       if(check>0){
           throw new ServiceException("医生："+newHisSchedule.getDoctName()+","+newHisSchedule.getSchedDate() +"已有排班，请勿重复排班！");
       }
        newHisSchedule.setCreateTime(DateUtils.getNowDate());
        return newHisScheduleMapper.insertNewHisSchedule(newHisSchedule);
    }

    /**
     * 修改newschedule
     * 
     * @param newHisSchedule newschedule
     * @return 结果
     */
    @Override
    public int updateNewHisSchedule(NewHisSchedule newHisSchedule)
    {
        newHisSchedule.setUpdateTime(DateUtils.getNowDate());
        return newHisScheduleMapper.updateNewHisSchedule(newHisSchedule);
    }

    /**
     * 批量删除newschedule
     * 
     * @param schedIds 需要删除的newschedule主键
     * @return 结果
     */
    @Override
    public int deleteNewHisScheduleBySchedIds(Long[] schedIds)
    {
        return newHisScheduleMapper.deleteNewHisScheduleBySchedIds(schedIds);
    }

    /**
     * 删除newschedule信息
     * 
     * @param schedId newschedule主键
     * @return 结果
     */
    @Override
    public int deleteNewHisScheduleBySchedId(Long schedId)
    {
        return newHisScheduleMapper.deleteNewHisScheduleBySchedId(schedId);
    }
}
